package com.aube.push;

import android.content.Context;

import com.aube.StaticApplicationContext;
import com.huyn.baseframework.utils.SharedPrefUtil;
import com.xiaomi.mipush.sdk.MiPushClient;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by huyaonan on 16/7/27.
 */
public class PushSetting {

    public static final String PUSH_STATUS = "PUSH_STATUS";
    public static final String PUSH_PARAM = "PUSH_PARAM";

    public static final String PUSH_REGIST_SUCCESS = "PUSH_REGIST_SUCCESS";

    public static boolean isPushOn(Context context) {
        boolean state =  SharedPrefUtil.getInstance(context).getBool(PUSH_STATUS, true);
        return state;
    }

    public static void togglePush(Context context, boolean on) {
        SharedPrefUtil.getInstance(context).putBool(PUSH_STATUS, on);
    }

    public static void registPush(Context context) {
        if(PushPhoneModel.getInstance(context).isXiaomi()) {
            registMiPush(context, StaticApplicationContext.MI_PUSH_ID, StaticApplicationContext.MI_PUSH_KEY);
        } else {
            resumeJPush(context);
        }
    }

    public static void unregistPush(Context context) {
        if(PushPhoneModel.getInstance(context).isXiaomi()) {
            unregistMiPush(context);
        } else {
            stopJPush(context);
        }
    }

    public static void registMiPush(Context context, String id, String key) {
        MiPushClient.registerPush(context, id, key);

        togglePush(context, true);
    }

    public static void unregistMiPush(Context context) {
        MiPushClient.unregisterPush(context);

        togglePush(context, false);
    }

    public static void resumeJPush(Context context) {
        JPushInterface.resumePush(context);
        togglePush(context, true);
    }

    public static void stopJPush(Context context) {
        JPushInterface.stopPush(context);
        togglePush(context, false);
    }

}
